<template>
  <div id='reply' class="reply">

    <orderStatistics :myInfo ='myInfo' :roleID='roleID'  @getData='getData'/>

    <el-popover placement="left" trigger="click">
      <template>
        <el-checkbox v-model="checked" @change="selectArr">全选</el-checkbox>
        <br />
        <el-checkbox v-model="checked12">订单耗时</el-checkbox>
        <br />
        <el-checkbox v-model="checked1">订单编号</el-checkbox>
        <br />
        <!-- <el-checkbox v-model="checked2">答复类型</el-checkbox>
        <br /> -->
        <el-checkbox v-model="checked3">审查意见</el-checkbox>
        <br />
        <el-checkbox v-if="roleID !== 2" v-model="checked4">代理人</el-checkbox>
        <br v-if="roleID !== 2">
        <el-checkbox v-model="checked5">答复意见</el-checkbox>
        <br />
        <el-checkbox v-model="checked6">申请号</el-checkbox>
        <br />
        <el-checkbox v-model="checked11">申报名称</el-checkbox>
        <br />
        <el-checkbox v-model="checked7">提交日期</el-checkbox>
        <br />
        <el-checkbox v-model="checked8">更新时间</el-checkbox>
        <br />
        <el-checkbox v-model="checked9">流程状态</el-checkbox>
      </template>
      <el-button style="float: right;margin-bottom: 5px;margin-top: 0;" slot="reference" icon="el-icon-arrow-down">显示字段</el-button>
    </el-popover>

    <!-- <el-input v-model="searchText" @input='searchTextChange' placeholder="请输入内容"></el-input> -->

    <!-- 列表查找 -->
    <span class="down-execel">
      <!-- <Poptip v-model="showFilter" placement="bottom-end" @on-popper-show ='getAllAgent'> -->
      <Poptip v-model="showFilter" placement="bottom-end" @on-popper-show ='getAllAgent'>
        <i class="el-icon-search poptip-condition-add"></i>
        <a href="javascript:;" class='poptip-condition-add'>列表查找</a>
        <div slot="content">
          <Poptip v-model="showFilterCondition" placement="bottom-start" class='poptip-condition'>
            <i class="el-icon-plus"></i>
            <a href="javascript:;">添加过滤条件</a>

            <div slot="content" class="condition-list">
              <ul>
                <template v-if='roleID == 2' >
                  <li v-for="(item, index) in columns" :key="index" class='poptip-condition-item' @click="addFilterCondition(item)">{{item.label}}</li>
                </template>
                <li v-else v-for="(item, index) in columns2" :key="index" class='poptip-condition-item' @click="addFilterCondition(item)">{{item.label}}</li>
              </ul>
            </div>
          </Poptip>

          <el-form :model="conditionForm" ref="conditionForm" label-min-width="120px" class="demo-dynamic" @submit.native.prevent>
            <el-form-item v-for="(condition, index) in conditionForm.condition" :label="condition.label" :key="condition.key"
              :prop="'condition.' + index + '.value'" :rules="{
                  required: true, message: condition.label + '不能为空', trigger: 'blur'
                }">
              <el-select v-if='condition.label === "流程状态"' v-model="condition.value" placeholder="请选择流程状态" size="small">
                <el-option label="等待答复" value="等待答复"></el-option>
                <el-option v-if="roleID != 2" label="已答复" value="已答复"></el-option>
                <el-option label="等待补正" value="等待补正"></el-option>
                <el-option v-if="roleID != 2" label="已补正" value="已补正"></el-option>
                <el-option label="发明人确认答复中" value="发明人确认答复中"></el-option>
                <el-option label="发明人确认补正中" value="发明人确认补正中"></el-option>
              </el-select>
              <el-select v-else-if='condition.label === "专利类型"' v-model="condition.value" placeholder="请选择专利类型" size="small">
                <el-option label="发明专利" value="F"></el-option>
                <el-option label="实用新型" value="S"></el-option>
                <el-option label="外观设计" value="W"></el-option>
                <!-- <el-option label="不确定" value="不确定"></el-option> -->
              </el-select>
              <el-select
                size="small"
                filterable
                v-model="condition.value"
                v-else-if='condition.label === "代理人"'>
                <el-option
                  v-for="item in agentOptions"
                  :key="item.id"
                  :label="item | agentNumAddName"
                  :value="item.id">
                </el-option>
              </el-select>

              <el-date-picker
                v-model="submitTime"
                type="daterange"
                placeholder="选择日期"
                value-format="yyyy-MM-dd"
                size="small"
                @change = 'changInput'
                :validate-event='false'
                v-else-if='condition.label === "提交日期"'>
              </el-date-picker>
              <el-date-picker
								v-model="updated_at"
								type="daterange"
								placeholder="选择日期"
								value-format="yyyy-MM-dd"
								:validate-event='false'
								@input = 'changInput'
								size="small"
								v-else-if='condition.label === "更新时间"'>
							</el-date-picker>

              <el-input v-else size="small" v-model="condition.value" @keyup.enter.native="submitsearch('conditionForm')"></el-input>
              <el-button @click.stop="removeDomain(condition)" size="mini">删除</el-button>
            </el-form-item>
          </el-form>
          <div class="btns">
            <el-button @click="submitsearch('conditionForm')" size="mini">查询</el-button>
            <el-button @click="resetForm('conditionForm')" size="mini">重置</el-button>
          </div>
        </div>
      </Poptip>
    </span>

    <el-table
      ref="orderTb"
      :data="tableData"
      border
      style="width: 100%"
      v-loading="loading"
      class="end_table"
      height="87%"
      @sort-change='tableSortChange'
      @row-click="lookOrder">
      <el-table-column show-overflow-tooltip prop="id" label="ID" min-width="60" align="left" v-if='checked99'>
        <template slot-scope="scope">{{(scope.$index+1)+(currentPage-1)*tableSize }}</template>
      </el-table-column>
      <el-table-column show-overflow-tooltip v-if="checked12" label="订单耗时(天)" prop="reply_time" min-width="140" align="left" sortable='custom'>
        <template slot-scope="scope">
          <span v-if="getTimeConsuming(scope.row) > 20">
            <span class="font_danger">{{ getTimeConsuming(scope.row)  }}</span>
          </span>
          <span v-else> {{ getTimeConsuming(scope.row)  }} </span>
        </template>
      </el-table-column>
      <el-table-column show-overflow-tooltip v-if="checked1" prop="order_number" label="订单编号" min-width="180" align="left" sortable='custom'></el-table-column>
      <el-table-column show-overflow-tooltip v-if="checked9" prop="status" label="流程状态" min-width="110" sortable='custom' align="left">
        <template slot-scope="scope">
          {{ scope.row.status }}
        </template>
      </el-table-column>
      <el-table-column show-overflow-tooltip v-if="checked10" prop='type' label="专利类型" min-width="110" align="left" sortable='custom'>
        <template slot-scope="scope">
          {{scope.row.type == 'F' ? '发明专利' : (scope.row.type == 'S' ? '实用新型' : '外观设计')}}
        </template>
      </el-table-column>
      <el-table-column show-overflow-tooltip v-if="checked6" prop='application_number' label="申请号" min-width="160" align="left" sortable='custom'></el-table-column>
      <el-table-column show-overflow-tooltip v-if="checked11" prop='name' label="申报名称" min-width="180" align="left" sortable='custom'></el-table-column>
      <el-table-column show-overflow-tooltip v-if="checked4 && roleID !== 2" prop='agent' label="代理人" min-width="140" align="left" sortable='custom'>
        <template slot-scope="scope">
          <!-- <span  v-if='scope.row.order'>{{ scope.row.order.agent.name }}</span> -->
          <span  v-if='scope.row'>{{ scope.row.agent | agentNumAddName}}</span>
        </template>
      </el-table-column>
      <el-table-column v-if="checked3" prop='opinion_file' label="审查意见/补正文件" min-width="170" align="left">
        <template slot-scope="scope">
          <div class='flie-hid'>
            <a v-for="item in scope.row.opinionFile" :key="item.id" :href="baseUrl +'/api/download?path=' + item.file +'/'+ item.path"
              :download="item.path" :title="item.path" class="el-icon-tickets file_sh"></a>
          </div>
        </template>
      </el-table-column>
      <el-table-column v-if="checked5" prop='answer_file' label="答复意见" min-width="150" align="left">
        <template slot-scope="scope">
          <div class='flie-hid'>
            <a v-for="item in scope.row.answerFile" :key="item.id" :href="baseUrl +'/api/download?path=' + item.file +'/'+ item.path"
              :download="item.path" :title="item.path" class="el-icon-tickets file_sh"></a>
          </div>
        </template>
      </el-table-column>
      <el-table-column show-overflow-tooltip v-if="checked7" prop='status_submited_at' label="提交日期" min-width="160" align="left" sortable='custom'>
        <template slot-scope="scope">
          {{ scope.row | getPost }}
        </template>
      </el-table-column>
      <el-table-column show-overflow-tooltip v-if="checked8" prop='status_updated_at' label="更新时间" min-width="160" align="left" sortable='custom'>
        <template slot-scope="scope">
          {{ scope.row | getAnswerUpdateTime }}
        </template>

      </el-table-column>
      <el-table-column :fixed="isFixed" v-if="roleID == 2 && checked99" width="100" align="center" label="操作">
				<template slot-scope="scope">
					<el-button type="primary" size="small" :disabled="scope.row.status == '发明人确认答复中' || scope.row.status == '发明人确认补正中'" @click.stop="answer(scope.row)" v-no-more-click:3000>{{ (scope.row.status == '等待答复' || scope.row.status == '发明人确认答复中') ? '答复' : '补正' }}</el-button>
				</template>
			</el-table-column>
    </el-table>

    <el-pagination
      class="pagination"
      @size-change="handleSizeChange"
      @current-change="handleCurrentChange"
      :current-page="currentPage"
			:page-sizes="pageSizes"
      :page-size="Number(pageSize)"
      layout="total, sizes, prev, pager, next, jumper"
      :total="total">
    </el-pagination>

    <el-dialog title="上传答复文件" center @close = 'sendAnswerClose' :visible.sync="showSendAnswer" class="sendAnswer">
      <template v-if="answerData">
        <template v-if="answerData.operations && answerData.operations.length">
          <el-timeline class="messageList">
            <el-timeline-item
              v-for="(item, index) in answerData.operations"
              :key="index"
              :timestamp="item.created_at"
            >
              <el-card class="messagebox">
                <Tooltip content="点我回复" class="fr">
                  <i class="el-icon-chat-dot-round ml5" @click="showTextarea(item, index)"></i>
                </Tooltip>
                <div class="agent_item clearfloat" v-if="item.role_id == '2'">
                  <span class="item_user fr">代理人</span>
                  <span class="item_time fr">{{item.created_at}}</span>
                  <div class="item_message messageBackground_r fr">
                    <span>{{item.operation_record}}</span>
                  </div>
                </div>
                <div v-else class="item">
                  <span class="item_time">{{item.created_at}}</span>
                  <span class="item_user">发明人</span>
                  <div class="item_message messageBackground_l">
                    <span>{{item.operation_record}}</span>
                  </div>
                </div>
                <div v-for="(agent, index2) in item.reply_message" :key="index2">
                  <div class="agent_item clearfloat" v-if="agent.role_id == '2'">
                    <span class="item_user fr">代理人</span>
                    <span class="item_time fr">{{agent.created_at}}</span>
                    <div class="item_message messageBackground_r fr">
                      <span>{{agent.operation_record}}</span>
                    </div>
                  </div>
                  <div v-else class="item">
                    <span class="item_time">{{agent.created_at}}</span>
                    <span class="item_user">发明人</span>
                    <div class="item_message messageBackground_l">
                      <span>{{agent.operation_record}}</span>
                    </div>
                  </div>
                </div>
                <div v-if="item.show_input" class="clearfloat mt20">
                  <el-input type="textarea" :rows="4" placeholder="请输入内容" v-model="replyMessage"></el-input>
                  <el-button class="fr mt10" type="primary" @click="submit(item)">发送</el-button>
                  <!-- <el-button class="fr mt10 mr10" @click="resets ">重置</el-button> -->
                </div>
              </el-card>
            </el-timeline-item>
          </el-timeline>
        </template>
      </template>
      <el-upload
				class="upload"
				:action="iploadULR"
				:on-remove="handleRemove"
				:on-change="handleChange"
				:http-request="uploadSectionFile"
				multiple
				:auto-upload="true"
				:limit="1"
				:file-list="fileList">
				<el-button size="small" type="success">{{`选择${setBtnText}文件`}}</el-button>
				<div slot="tip" class="el-upload__tip">最多只能上传一个文件,如果有多个文件,请将文件夹压缩后上传</div>

			</el-upload>
      <el-button size="small" type="primary"  :loading="sendAnswerLoading" @click="submitAnswerFile" class='btn-send' v-no-more-click:3000>{{`发送${setBtnText}文件`}}</el-button>
    </el-dialog>
  </div>
</template>

<script>
import axios from "axios"
import { getMyInfo } from "~/api/user";
import { getTimeConsuming } from '~/util/index'
import orderStatistics from "~/components/orderStatistics"

import orderFn from './getOrderList'

export default {
  data () {
    return {
      loading: false,
      roleID: 1,
      tableData: [],
      isFixed: "right",
      checked:true,
      checked1: true,
      checked2: true,
      checked3: true,
      checked4: true,
      checked5: true,
      checked6: true,
      checked7: true,
      checked8: true,
      checked9: true,
      checked10: true,
      checked11: true,
      checked12: true,
      checked99: true,
      // 分页
      tableSize: 25, //一页几条
      pageSizes: [25, 50], //一页可以几条
      total: 0,
      showSendAnswer: false,
      iploadULR: '',
      fileListV: [],
      fileList: [],
      sendAnswerLoading: false,
      finalAnswer: '',
      baseUrl: global.baseurl,
      paramsByOrder: {
        status: "已补正,已答复,等待补正,等待答复,发明人确认答复中,发明人确认补正中",
      },
      isAnswer: '',
      showFilter: false, // 控制显示筛选条件
      showFilterCondition: false,
      showSendEmail: false,
      conditionForm: {
        condition: []
      }, //筛选条件
      columns: [
        {
          label: '订单编号',
          id: 1,
          parameter: 'order_number'
        },
        {
          label: '流程状态',
          id: 2,
          parameter: 'status'
        },
        {
          label: '专利类型',
          id: 3,
          parameter: 'type'
        },
        {
        	label: '申请号',
        	id: 4,
        	parameter: 'application_number'
        },
        {
        	label: '申报名称',
        	id: 5,
        	parameter: 'name'
        },
        {
          label: '提交日期',
          id: 7,
          parameter: 'subimt_time'
        },
        {
          label: '更新时间',
          id: 8,
          parameter: 'updated_at'
        },
      ],
      columns2: [
        {
          label: '订单编号',
          id: 1,
          parameter: 'order_number'
        },
        {
          label: '流程状态',
          id: 2,
          parameter: 'status'
        },
        {
          label: '专利类型',
          id: 3,
          parameter: 'type'
        },
        {
        	label: '申请号',
        	id: 4,
        	parameter: 'application_number'
        },
        {
        	label: '申报名称',
        	id: 5,
        	parameter: 'name'
        },
        {
        	label: '代理人',
        	id: 6,
        	parameter: 'agent_id'
        },
        {
          label: '提交日期',
          id: 7,
          parameter: 'subimt_time'
        },
        {
          label: '更新时间',
          id: 8,
          parameter: 'updated_at'
        },
      ],
      submitTime: [],
      agentOptions: [],
      updated_at: [],
      searchText: '',
      myInfo: {
        back_total: 0
      },
      pageSize: 25,
      currentPage: 1, //目前在第几页
      isStatistics: true,
      isMyorder: null,
      answerData: null,
      replyMessage: ''
    }
  },
  components:{
    orderStatistics
  },
  created () {
    // this.getData()
    this.roleID = this.$store.state.user.role_id

  },
  computed: {
    checkedArr() {
      let arr = [this.checked1, this.checked2, this.checked3, this.checked4, this.checked5, this.checked6, this.checked7, this.checked8, this.checked9, this.checked10, this.checked11, this.checked12]
      return arr
    },
    setBtnText () {
      if(this.isAnswer) {
        return '答复'
      } else {
        return '补正'
      }
    }
  },
  async asyncData({
			$axios,
			store,
			route
		}) {
    // const STATUS =
    let paramsByOrder = {
      status: "已补正,已答复,等待补正,等待答复,发明人确认答复中,发明人确认补正中",
      page: 1,
      perPage: 25
    }

    // if (store.state.user.role_id == 4) {
    //   paramsByOrder.status = '已答复,等待答复'
    // }
    if (store.state.user.role_id == 2) {
      paramsByOrder.status = '等待答复,等待补正,发明人确认答复中,发明人确认补正中'
      paramsByOrder.agent_id = store.state.user.id;
    }
    return orderFn.getAnswerList($axios, store, paramsByOrder)

  },
  methods: {
    selectArr(val) {
      if (val) {
            this.checked1 = true;
            this.checked2 = true;
            this.checked3 = true;
            this.checked4 = true;
            this.checked5 = true;
            this.checked6 = true;
            this.checked7 = true;
            this.checked8 = true;
            this.checked9 = true;
            this.checked10 = true;
            this.checked11 = true;
            this.checked12 = true;

          } else {
            this.checked1 = false;
            this.checked2 = false;
            this.checked3 = false;
            this.checked4 = false;
            this.checked5 = false;
            this.checked6 = false;
            this.checked7 = false;
            this.checked8 = false;
            this.checked9 = false;
            this.checked10 = false;
            this.checked11 = false;
            this.checked12 = false;
          }
    },
    async tableDataRefresh() {
      if (this.roleID == 2) {
        this.paramsByOrder.agent_id = this.$store.state.user.id;
        this.paramsByOrder.status = '等待答复,等待补正,发明人确认答复中,发明人确认补正中'
      }
      let data = await orderFn.getAnswerList(this.$axios, this.$store, this.paramsByOrder);
      for (let key in data) {
        this[key] = data[key]
      }
    },
    async getData (args) {
      let params = {
        perPage: this.pageSize,
        page: this.currentPage,
        status: "已补正,已答复,等待补正,等待答复,发明人确认答复中,发明人确认补正中"
      }
      if (this.roleID == 2) {
        params.status = '等待答复,等待补正,发明人确认答复中,发明人确认补正中'
        params.agent_id = this.$store.state.user.id;
      }
      // if (this.roleID == 4) {
      //   params.status = '已答复,等待答复'
      // }
      if (args) {
        params = {...params, ...args}
        this.paramsByOrder = args
        this.currentPage = args.page
      }
      let data = await orderFn.getAnswerList(this.$axios, this.$store, params)

      for (let key in data) {
        this[key] = data[key]
      }
    },
    lookOrder() {},
    // 表格排序
    async tableSortChange(column) {
      if (column.order == 'ascending') {
        this.paramsByOrder.sort_str = column.prop
        this.paramsByOrder.sort_order = 'asc'
      } else if (column.order == 'descending') {
        this.paramsByOrder.sort_str = column.prop
        this.paramsByOrder.sort_order = 'desc'
      } else {
        delete this.paramsByOrder.sort_str
        delete this.paramsByOrder.sort_order
      }
      this.loading = true
      this.currentPage = 1
      this.tableDataRefresh()
    },
    //选择一页几条
    handleSizeChange(size) {
      this.pageSize = size
      this.paramsByOrder.page = 1
      this.paramsByOrder.perPage = size
      this.tableDataRefresh()
    },
    handleCurrentChange(val) {
      this.currentPage = val
      this.paramsByOrder.page = val
      this.tableDataRefresh()
    },
    resetForm(formName) {
      this.$refs[formName].resetFields()
      this.$refs['orderTb'].clearSort()
      this.conditionForm.condition.forEach(v => {
        if (v.value) {
          v.value = null
        }
      });
      this.showFilterCondition = false
      this.submitTime = []
      this.updated_at = []
      this.currentPage = 1
      this.paramsByOrder = {
        status: "已补正,已答复,等待补正,等待答复,发明人确认答复中,发明人确认补正中",
      }
      this.$nextTick(() => {
        this.$refs[formName].clearValidate()
      })
      // this.getData()
      // this.showFilter = false
    },
    search() {
      this.paramsByOrder.status = this.$store.state.user.role_id == 2?"等待答复,等待补正,发明人确认答复中,发明人确认补正中":"已补正,已答复,等待补正,等待答复,发明人确认答复中,发明人确认补正中"
      if (this.$store.state.user.role_id == 2) {
        this.paramsByOrder.agent_id = this.$store.state.user.id
      }
      // if(this.$store.state.user.role_id == 4) {
      //   this.paramsByOrder.status = '已答复,等待答复'
      // }
      for (var i = 0; i < this.conditionForm.condition.length; i++) {
        let a = this.conditionForm.condition[i].parameter
        if (this.conditionForm.condition[i].parameter === 'subimt_time') {
          this.paramsByOrder.status_submited_at_start = this.submitTime[0]
          this.paramsByOrder.status_submited_at_end = this.submitTime[1]
        }
        if (this.conditionForm.condition[i].parameter === 'updated_at') {
          this.paramsByOrder.status_updated_at_start     = this.updated_at[0]
          this.paramsByOrder.status_updated_at_end = this.updated_at[1]
        }
        this.paramsByOrder[a] = this.conditionForm.condition[i].value
      }

      delete this.paramsByOrder.subimt_time
      // 处理分页数据
      delete this.paramsByOrder.page

      // 处理排序状态
      delete this.paramsByOrder.sort_str
      delete this.paramsByOrder.sort_order
      this.$refs['orderTb'].clearSort()
      this.paramsByOrder.page = 1
      this.getData(this.paramsByOrder)
      this.showFilter = false
    },
    getAllAgent() {
      this.$axios.get('api/user/agent/all')
        .then(res => {
          if (res.data.code == 200) {
            this.agentOptions = res.data.data
          }
        })
        .catch(err => {
          this.$message({
            type: "err",
            message: err
          });
        });
    },

    answer (row) {
      if (row.status == '等待答复') {
        this.isAnswer = true
      } else {
        this.isAnswer = false
      }
      this.$nextTick(() => {
        this.answerData = row
      })
      this.showSendAnswer = true
      this.finalAnswer = row.id
      this.isMyorder = row.order.is_distribution
    },
    sendAnswerClose () {
      this.fileList = []
			this.fileListV = []
    },
    handleRemove(file, fileList) {
			this.fileListV = fileList
    },
    handleChange(file, fileList) {
      let tempList = [];//可以上传的文件
      let that = this;
      let canUpload = true;//是否可以上传
      let fileName,
          fileNameArr,
          arrLen,
          pos,
          lastName,
          orderNum =''
      for(let i = 0;i<fileList.length;i ++){
        // //验证文件类型
        fileName = fileList[i].name;
        pos = fileName.lastIndexOf(".")
        lastName = fileName.substring(pos, fileName.length)
        tempList.push(fileList[i])
      }
      this.fileListV.splice(0,this.fileListV.length,...tempList)
      fileList.splice(0, fileList.length,...tempList)
      return
    },
    uploadSectionFile(params) {

    },
    submitAnswerFile () {
      this.sendAnswerLoading = true
      let list = document.getElementsByClassName(
        "el-upload-list__item is-ready"
      );
      if (list.length == 0) {
        this.$message({
          type: "warning",
          message: "请选择需要上传的文件！"
        });
        return
      }
      // FormData 对象
      let form = new FormData()
      // 文件对象
      form.append('finalAnswer', this.finalAnswer)
      form.append('file', this.fileListV[0].raw);
      let url = ''
      if (this.isMyorder == 3) {
        url = `/api/finals/${this.finalAnswer}/agent/my/answer`
      } else {
        url = `/api/finals/${this.finalAnswer}/agent/answer`
      }
      axios({
        method: "post",
        url: this.baseUrl + url,
        data: form,
        headers: {
          "Content-Type": "multipart/form-data",
          Authorization: "Bearer " + this.$store.state.token
        }
        }).then(res => {
        if (res.data.status == "success") {
          this.$message({
            type: "success",
            message: "上传答复文件成功"
          })
          this.sendAnswerLoading = false
          this.fileListV = []
          this.showSendAnswer = false
          this.search()
        } else {
          this.$message({
            type: "error",
            message: res.data.message
          });
          this.fileListV = []
        }
      });
    },

    // 添加条件筛选
    addFilterCondition(item) {
      let filterItem = {
        value: '',
        label: item.label,
        parameter: item.parameter,
        key: Date.now()
      }

      if (this.conditionForm.condition.length > 0) {
        let conditionlabels = []
        for (let i = 0; i < this.conditionForm.condition.length; i++) {
          conditionlabels.push(this.conditionForm.condition[i].label)
        }
        let Check = conditionlabels.indexOf(item.label)
        Check == -1 ? this.conditionForm.condition.push(filterItem) : this.$message.error('请勿重复添加')
      } else {
        this.conditionForm.condition.push(filterItem)
      }

      this.showFilterCondition = false
    },
    submitsearch(formName) {
      let that = this
      this.$refs[formName].validate((valid, prop) => {
        // this.$refs[formName].clearValidate();
        let props = []
        for (let k in prop) {
          props.push(prop[k][0].field)
          if (prop[k][0].message = '提交日期') {
            if (that.submitTime) {
              if (that.submitTime.length > 0) {
                that.$refs[formName].clearValidate([prop[k][0].field])
                // that.search()
                let timeIndex = props.indexOf('提交日期')
                props.splice(timeIndex, 1)
              }
            } else {
              return false
            }

          }

          if (prop[k][0].message = '更新时间不能为空') {
            if (that.updated_at) {
                if(	that.updated_at.length > 0	) {
                that.$refs[formName].clearValidate([prop[k][0].field])
                // that.search()
                let timeIndex = props.indexOf('更新时间不能为空')
                props.splice(timeIndex, 1)
              }
            } else return false

          }
        }
        if (props.length) {
          that.$refs[formName].validateField(props, (valid2) => {
            if (valid2) {
              return false;
            } else {
              that.search()
            }

          })
        } else {
          that.search()
        }
      })
    },
    removeDomain(item) {
      this.showFilter = true
      delete this.paramsByOrder[item.parameter]
      let index = this.conditionForm.condition.indexOf(item)
      if (index !== -1) {
        this.conditionForm.condition.splice(index, 1)
      }
      if (item.label === '提交日期') {
        this.submitTim = []
        delete this.paramsByOrder.status_submited_at_start
				delete this.paramsByOrder.status_submited_at_end
      }

      if (item.label === '更新时间') {
        this.updated_at = []
        delete this.paramsByOrder.status_updated_at_start
				delete this.paramsByOrder.status_updated_at_end
      }
      this.search()
    },
    changInput () {
      this.$refs['conditionForm'].clearValidate();
    },
    searchTextChange () {
    },
    getTimeConsuming(val) {
      return getTimeConsuming(val)
    },
    submit(item) {
      if (this.replyMessage == "") {
        this.$message({
          message: "请输入消息",
          type: "warning"
        });
      } else {
        this.submitPost(item)
      }
    },
    showTextarea(item, index) {
      for(let i = 0; i < this.answerData.operations.length; i++) {
        this.answerData.operations[i].show_input = false;
        if (i == index) {
          this.answerData.operations[i].show_input = true
        }
      }
    },
    submitPost(data) {
      let params = {
        pid: data.id,
        operation_record: this.replyMessage,
        // type: 'inventor'
      }
      this.$axios
        .post(`api/finals/reply_message`, params)
        .then(res => {
          if (res.data.code == 200) {
            this.$message({
              type: "success",
              message: "回复成功！"
            });
            this.replyMessage = ''
            this.search()
            this.showSendAnswer = false
          } else {
            this.$message({
              type: "error",
              message: res.data.message
            });
          }
        })
        .catch(e => {
          console.log(e);
        });
    },
  },
  watch: {
    checkedArr: {
      handler: function(val) {
        if (val.some(v => v == false)) {
          this.checked = false
        } else {
          this.checked = true
        }
        if (val.every(v => v == false)) {
					this.checked99 = false
				} else {
					this.checked99 = true
				}
      },
      deep: true
    }
  }
}
</script>

<style lang='less' scoped>
  .reply {
    height: 100%; //撑满表格
    .el-table {
      width: 99.9% !important;
    }
  }
  .tableLastCol {
		padding-right: 25px ;
		// padding-left: 25px !important;
  }
  .file_sh {
		font-size: 25px;
		margin-right: 10px;
  }
  .el-main .ivu-poptip .ivu-poptip-popper .ivu-poptip-content .ivu-poptip-inner {
		min-width: 450px;
		// height: 300px;
		overflow-y: scroll;
	}

	.el-dropdown {
		font-size: 12px;
		margin: 0 5px;
		color: #2d8cf0;
	}

	.el-main .poptip-condition .ivu-poptip-popper .ivu-poptip-content .ivu-poptip-inner {
		min-width: 180px;
	}

	.poptip-condition {
		display: block;
		margin-top: 10px;

		.poptip-condition-item {
			line-height: 25px;
			cursor: pointer;
		}

		.poptip-condition-add {
			font-size: 14px;
		}
	}

	.demo-dynamic {
		padding-left: 10px;

		.el-form-item {
			margin-bottom: 12px;
		}

		.el-input {
			width: 240px;
		}

		.el-date-editor {
			width: 240px;
		}

		.el-button {
			padding: 9px 15px;
			vertical-align: baseline;
		}

		.el-form-item__error {
			padding-top: 0;
		}
  }

  .down-execel {
		display: block;
		height: 40px;
		line-height: 40px;
		color: #333333;
		font-size: 14px;
		margin-right: 20px;
		float: right;
  }
  .sendAnswer {
    .el-dialog {
      max-height: 600px;
      overflow-y: auto;
    }
  }
  .messageList {
		.messagebox {
			width: 100%;
			background: #eef1f3;
		}

		.messageBackground_l {
			background: #fff;
		}
		.messageBackground_r {
			background: #c9e7ff;
		}
		.item {
			width: 100%;
			margin-bottom: 10px;
			.item_user {
				display: inline-block;
				width: 60px;
				font-size: 16px;
				font-weight: bold;
			}
			.item_message {
				max-width: calc(100% - 170px);
				display: inline-block;
				padding: 10px 15px;
				box-sizing: border-box;
				margin-left: 15px;
				border-radius: 5px;
				vertical-align: top;
				// margin-right: 90px;
			}
			.item_time {
				font-size: 12px;
				display: block;
				padding-left: 80px;
				margin-bottom: 5px;
				color: #ccc;
			}
			.deduction_message {
				margin: 20px 0 0 80px;
				max-width: calc(100% - 170px);
				padding: 10px 15px;
				border-radius: 5px;
			}
		}
		.agent_item {
			width: 100%;
			margin-bottom: 10px;
			position: relative;
			box-sizing: border-box;
			padding-top: 20px;
			.item_user {
				display: inline-block;
				width: 60px;
				font-size: 16px;
				font-weight: bold;
			}
			.item_time {
				position: absolute;
				right: 95px;
				top: 0px;
				font-size: 12px;
				display: block;
				// padding-right: 80px;
				margin-bottom: 5px;
				color: #ccc;
			}
			.item_message {
				max-width: calc(100% - 180px);
				display: inline-block;
				padding: 10px 15px;
				box-sizing: border-box;
				margin-right: 30px;
				border-radius: 5px;
				vertical-align: top;
				// margin-left: 80px;
			}
		}
	}
</style>
